The present invention relates to a memory rewriting system for rewriting data stored in a memory of a vehicle controller with another data transferred from an external rewriting device.
Vehicles are subjected to various types of control by an electronic control unit (hereafter referred to as xe2x80x9cECUxe2x80x9d). Such control includes engine-related control for an air fuel ratio, fuel injection amount, and emission as well as body-related control for a power window, an air bag, and an ABS. The ECU provides various types of control for the vehicle based on current conditions and traveling status of the vehicle sensed by various sensors mounted on the vehicle.
The ECU comprises a central processing unit (CPU), a ROM (Read Only Memory) that stores programs and data to be executed, a RAM (Random Access Memory) which provides a work area for execution and which stores results of computation, and an I/O interface for receiving signals from various sensors and transmitting control signals to various parts of the engine.
A system wherein the ROM comprises a rewritable memory, such as a flash memory, an EEPROM, or an EPROM, to allow a program or data therein to be rewritten through serial communication is known. Such a system comprises a rewriting device, a vehicle controller, and a serial communication path connecting them together. For example, Japanese Patent Application Laid-Open No. 63-223901 describes a method for changing a program stored in the EEPROM of the ECU in response to a request from an external device via a SCI (Serial Communication Interface) terminal with the ECU being mounted on the vehicle.
In such a system for rewriting a program through serial communication, the rewriting device assembles a plurality data blocks from program code of the program, and then serially transfers the data blocks to the vehicle controller. Each data block includes a partial program code. In order to inform the vehicle controller of a memory address at which a transferred partial program code is stored, one of the following method is typically employed:
1) the data blocks are serially transferred in an ascending order of address values of the program code.
2) a leading address of a partial program code is added to each data block. The data blocks are transferred in an arbitrary order.
There are, however, several problems with the above-mentioned methods. As to the method 1), program code must be transferred such that the entire memory area is rewritten with the transferred program code. This is because if the transfer is interrupted, it is hard to determine whether the interruption has take place due to the end of transfer of the program code or due to a failure in the communication path. This reduces the reliability of transfer. In the case all of the memory area is not used (it is very rare that all of the memory area is used), transfer of program code including free space results in a waste of time.
As to the method 2), the waste of time as occurring with the method 1) is resolved. Assume that the vehicle controller receives a partial program code specifying an address significantly separate from the preceding received address. For example, the vehicle controller receives 16 bytes starting with the address 1000 and then receives 10 bytes starting with the address 10100. It is hard to determine whether the portion between the two addresses is free space or the second address value has advanced by error. This reduces the reliability of transfer.
On the other hand, when the program code is transferred, particularly using serial communication, the transfer may be inaccurate due to disturbance such as electromagnetic waves.
Accordingly, both the ECU and the rewriting device require a mechanism for checking the transferred program code for consistency.
An object of the present invention is to provide a memory rewriting system that makes program transfer more reliable and more efficient without wasting time in program transfer.
Another object of the present invention is to provide a memory rewriting system that allows both a rewriting device and an ECU to check the consistency of a transferred program code.
According to one aspect of the invention, a rewriting device for transferring a first program to a vehicle controller to rewrite a second program stored in a memory of the vehicle controller with the first program is provided. The first program is transferred as data blocks. Each of the data blocks includes a program code field for a partial program code of the first program, a first address field for a leading address of the memory in which the partial program code is stored, and a second address field for a leading address of the memory in which the following partial program code to be transferred by another data block is to be stored. The vehicle controller can determine that a correct data block has been received by checking whether the received data block contains in the first address field the address that was included in the second address field of the preceding data block.
In one embodiment of the invention, the rewriting device further comprises a controller for assembling the data blocks. The controller can assemble the data blocks with a fixed length or a variable length. In the latter case, the data block can be assembled so as not to include free space. In another embodiment, the data block is assembled such that the length of the data block is determined based on the size of free space between partial program codes.
In one embodiment of the invention, the vehicle controller is further configured to compare a first address in the first address field of a current data block with a second address in the second address field of a preceding data block. The vehicle controller determines that the current data block is correct if the first address included in the current data block is equal to the second address included in the preceding data block.
In another embodiment of the invention, the vehicle controller is further configured to transfer the second address included in the preceding data block to the rewriting device if it is determined that the current data block is not correct. Thus, the vehicle requests the rewriting device to retransfer a correct data block. The program code is stored in the memory of the vehicle controller in a correct order, thereby enhancing the efficiency of program transfer.
In one embodiment of the invention, in response to the retransfer request from the vehicle controller, the rewriting device retransfers the correct data block if the second address transferred from the vehicle controller is within a predetermined range. The predetermined range may include an address value in the first address field of the data block transferred immediately before the retransfer request, an address value in the first address field of the data block preceding such data block, and an address value in the first address field of the data block that was to be transferred following such data block.
In another embodiment of the invention, in response to the retransfer request from the vehicle controller, the rewriting device retransfers data blocks of the first program from the beginning if a difference between the second address transferred from the vehicle controller and an address value in the first address field of the data block transferred immediately before the retransfer request is greater than a predetermined value.